//
// Created by 27531 on 2022/2/14.
//

#ifndef MYX264TEST_VIDEOCHANNEL_H
#define MYX264TEST_VIDEOCHANNEL_H
#include "pthread.h"
#include <android/log.h>
#include "x264.h"
#include <cstring>
#include "JavaCallHelper.h"
#define LOGI(...) __android_log_print(ANDROID_LOG_INFO,"hugang",__VA_ARGS__)

class VideoChannel {
public:
    VideoChannel();
    ~VideoChannel();
    void init();
    //创建x264编码器
    void setVideoEncInfo(int width, int height, int fps, int bitrate);
    //真正开始编码一帧数据
    void encodeData(int8_t *y, int8_t *u, int8_t *v, int ylength, int ulength, int vlength);
//    void loopCodecPacket();
    void close();
private:
    int mWidth;
    int mHeight;
    int mFps;
    int mBitrate;
    //    yuv-->h264 平台 容器 x264_picture_t=bytebuffer
    x264_picture_t *mPic_in = 0;
    x264_picture_t *mPic_out = NULL;
    //    编码器
    x264_t *mVideoCodec = 0;
    pthread_t mVideo_codec_thread;
    int mYSize;
    int mUVSize;
    JavaCallHelper* mJavaCallHelper = NULL;
    x264_nal_t *mPp_nals;

    pthread_mutex_t mMutex = PTHREAD_MUTEX_INITIALIZER;
    pthread_cond_t mCond = PTHREAD_COND_INITIALIZER;
    pthread_mutex_t mEncoder_mutex = PTHREAD_MUTEX_INITIALIZER;
    pthread_cond_t mEncoder_cond = PTHREAD_COND_INITIALIZER;
    int frame_count = 0;
};
#endif //MYX264TEST_VIDEOCHANNEL_H
